//
//  LZCurrentUserInfo.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/11/17.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZCurrentUserInfo.h"
#import "MJProperty.h"
#import "GVUserDefaults+LZProperties.h"

@implementation LZCurrentUserInfo

#pragma mark - 实现NSCoding协议的方法

-(id)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super init]) {
        self.userId = [aDecoder decodeObjectForKey:@"userId"];
        self.token = [aDecoder decodeObjectForKey:@"token"];
        self.sellerId = [aDecoder decodeObjectForKey:@"sellerId"];
        self.cellphone = [aDecoder decodeObjectForKey:@"cellphone"];
        self.email = [aDecoder decodeObjectForKey:@"email"];
        self.sellerName = [aDecoder decodeObjectForKey:@"sellerName"];
        self.sellerPhoto = [aDecoder decodeObjectForKey:@"sellerPhoto"];
        self.userType = [aDecoder decodeObjectForKey:@"userType"];
        self.role = [aDecoder decodeObjectForKey:@"role"];
        
        self.merchantState = [aDecoder decodeIntegerForKey:@"merchantState"];
        
        self.hasPassword = [aDecoder decodeBoolForKey:@"hasPassword"];
        
    }
    return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:self.userId forKey:@"userId"];
    [aCoder encodeObject:self.token forKey:@"token"];
    [aCoder encodeObject:self.sellerId forKey:@"sellerId"];
    [aCoder encodeObject:self.cellphone forKey:@"cellphone"];
    [aCoder encodeObject:self.email forKey:@"email"];
    [aCoder encodeObject:self.sellerName forKey:@"sellerName"];
    [aCoder encodeObject:self.sellerPhoto forKey:@"sellerPhoto"];
    [aCoder encodeObject:self.userType forKey:@"userType"];
    [aCoder encodeObject:self.role forKey:@"role"];
    
    [aCoder encodeBool:self.hasPassword forKey:@"hasPassword"];
    
    [aCoder encodeInteger:self.merchantState forKey:@"merchantState"];
    
}


#pragma mark - 存用户信息

+(void)setUserInfoWithModel:(LZCurrentUserInfo*)model
{
    if (model == nil) {
        return;
    }
    // 序列化
    NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:model];
    [GVUserDefaults standardUserDefaults].userInfo = myEncodedObject;
}

#pragma mark - 获取存下的用户信息

+(LZCurrentUserInfo*)getUserInfoModel
{
    // 反序列化
    NSData *myEncodedObject = [GVUserDefaults standardUserDefaults].userInfo;
    if (myEncodedObject) {
        LZCurrentUserInfo *model = (LZCurrentUserInfo *)[NSKeyedUnarchiver unarchiveObjectWithData: myEncodedObject];
        return model;
    }
    
    return nil;
}
@end
